﻿Imports DTO
Public Class DAONhanVien
    Public Function LoadNV() As DataTable
        Dim sql As String
        sql = "select * from NhanVien ,TinhTrangNhanVien where STT=TinhTrang"
        Dim dt As DataTable
        dt = DataProvider.LoadSQL(sql)
        Return dt
    End Function
    Public Function LoadNV_MaNV(ByVal _ma As String) As DataTable
        Dim sql As String
        sql = "select * from NhanVien where MaNV= " + _ma.ToString()
        Dim dt As DataTable
        dt = DataProvider.LoadSQL(sql)
        Return dt
    End Function
    Public Sub AddNV(ByVal _nv As DTO.DTONhanVien)
        Dim sql As String
        sql = String.Format("insert into NhanVien values (N'{0}',N'{1}',1,'{2}',N'{3}'),{4}", _nv._sTen, _nv._sDiaChi, _nv._sCMND, _nv._sGioiTinh, _nv._iHeSoLuong)
        DataProvider.ExcuteQuery(sql)
    End Sub
    Public Sub UpdateNV(ByVal _nv As DTO.DTONhanVien)
        Dim sql As String
        sql = String.Format("update NhanVien set Ten = N'{0}' , DiaChi = N'{1}' , CMND = {2} , GioiTinh = N'{3}', HeSoLuong = {5} where MaNV = {4}", _nv._sTen, _nv._sDiaChi, _nv._sCMND, _nv._sGioiTinh, _nv._iMaNV, _nv._iHeSoLuong)
        DataProvider.ExcuteQuery(sql)
    End Sub
    Public Sub DelNV(ByVal _nv As DTO.DTONhanVien)
        Dim sql As String
        sql = "update NhanVien set TinhTrang = 3 where MaNV = " + _nv._iMaNV.ToString()
        DataProvider.ExcuteQuery(sql)
    End Sub
    Public Sub NVCu(ByVal _nv As DTO.DTONhanVien)
        Dim sql As String
        sql = "update NhanVien set TinhTrang = 1 where MaNV = " + _nv._iMaNV.ToString()
        DataProvider.ExcuteQuery(sql)
    End Sub

    Public Function LoadListNVTrucDAO() As List(Of DTONhanVien)
        Dim sql As String = "Select * from NhanVien where TinhTrang = 2"
        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        Dim _listNVDangTruc As New List(Of DTONhanVien)
        For Each row As DataRow In dt.Rows
            Dim _nhanVienDTO As New DTONhanVien()
            _nhanVienDTO._iMaNV = Integer.Parse(row("MaNV").ToString())
            _nhanVienDTO._sTen = row("Ten").ToString()
            _nhanVienDTO._sDiaChi = row("DiaChi").ToString()
            _nhanVienDTO._iTinhTrang = row("TinhTrang").ToString()
            _nhanVienDTO._sCMND = row("CMND").ToString()
            _nhanVienDTO._sGioiTinh = row("GioiTinh").ToString()
            _listNVDangTruc.Add(_nhanVienDTO)
        Next
        Return _listNVDangTruc
    End Function

    Public Function LoadTableNVTrucDAO() As DataTable
        Dim sql As String = "Select * from NhanVien where TinhTrang = 2"
        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        Return dt
    End Function

    Public Function LayThongTinNhanVienDAO(ByVal _maNV As Integer) As DTONhanVien
        Dim _nhanVienDTO As New DTONhanVien()
        If (_maNV = 0) Then
            Return _nhanVienDTO
        End If
        Dim sql As String = "Select * from NhanVien where MaNV = " & _maNV
        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        '_iMaNV = New Integer()
        '_sTen = New String()
        '_sDiaChi = New String()
        '_iTinhTrang = New String()
        '_sCMND = New String()
        '_sGioiTinh = New String()        
        _nhanVienDTO._iMaNV = _maNV
        _nhanVienDTO._iTinhTrang = dt.Rows(0)("TinhTrang").ToString()
        _nhanVienDTO._sCMND = dt.Rows(0)("CMND").ToString()
        _nhanVienDTO._sDiaChi = dt.Rows(0)("DiaChi").ToString()
        _nhanVienDTO._sGioiTinh = dt.Rows(0)("GioiTinh").ToString()
        _nhanVienDTO._sTen = dt.Rows(0)("Ten").ToString()

        Return _nhanVienDTO

    End Function

End Class
